/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-03
 * Time: 17:44
 */

// https://leetcode.cn/problems/day-of-the-year/submissions/
public class Solution2 {
    public static int dayOfYear(String date) {
        String[] yMD = date.split("-");
        int[] dayInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (isLeapYear(Integer.parseInt(yMD[0]))) {
            dayInMonth[2] = 29;
        }
        int res = 0;
        for (int i = 0; i < Integer.parseInt(yMD[1]); i++) {
            res += dayInMonth[i];
        }
        res += Integer.parseInt(yMD[2]);
        return res;
    }
    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }

    public static void main(String[] args) {
        String date = "2019-02-10";
        System.out.println(dayOfYear(date));
    }
}
